﻿using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
/// SFUI_ScrollRect组件[Drag]
/// </summary>
public partial class SFUI_ScrollRect
{
    /// <summary>
    /// 在Item变更后阻止拖拽的帧数【在拖动时保证不乱滚动的关键】
    /// </summary>
    int mStopDragFrameAfterItemChange = 0;
    /// <summary>
    /// 是否在拖拽
    /// </summary>
    bool mIsDrag = false;

    #region OnBeginDrag 开始拖拽
    /// <summary>
    /// 开始拖拽
    /// </summary>
    /// <param name="_eventData">数据</param>
    public override void OnBeginDrag(PointerEventData _eventData)
    {
        base.OnBeginDrag(_eventData);
        mIsDrag = true;
    }
    #endregion

    #region OnDrag 拖拽
    /// <summary>
    /// OnDrag
    /// </summary>
    /// <param name="_eventData">数据</param>
    public override void OnDrag(PointerEventData _eventData)
    {
        if (mStopDragFrameAfterItemChange > 1)
        {
            OnEndDrag(_eventData);
            mStopDragFrameAfterItemChange--;
        }
        else if (mStopDragFrameAfterItemChange == 1)
        {
            OnBeginDrag(_eventData);
            mStopDragFrameAfterItemChange--;
        }
        if (mStopDragFrameAfterItemChange <= 0)
        {
            base.OnDrag(_eventData);
        }
    }
    #endregion

    #region OnEndDrag 结束拖拽
    /// <summary>
    /// 结束拖拽
    /// </summary>
    /// <param name="_eventData">数据</param>
    public override void OnEndDrag(PointerEventData _eventData)
    {
        base.OnEndDrag(_eventData);
        mIsDrag = false;
    }
    #endregion

    #region OnStopDrag 停止拖拽
    /// <summary>
    /// 停止拖拽
    /// </summary>
    void OnStopDrag()
    {
        mStopDragFrameAfterItemChange = 2;
    }
    #endregion
}
